package control;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Projeto;
import model.UsuarioCT;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import dao.ProjetoDAO;
import dao.UsuarioProjetoDAO;

public class ListaRemoveAction extends Action {
	
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws SQLException {
		
		HttpSession session = request.getSession();
		UsuarioCT usuario = (UsuarioCT)session.getAttribute("usuario");
		
		String nomeUnix = request.getParameter("nomeUnix");
		Facade facade = Facade.getInstance();
		if (nomeUnix != null) {
			facade.removeProjeto(nomeUnix);
			//usuario.removerProjeto(nomeUnix);
			//atualiza sessao apos a remocao do usuario
			//session.setAttribute("usuario", usuario);
		}
		List<Projeto> projetosAdmin = facade.listaProjetos(usuario.getUsuario(),UsuarioCT.ADMINISTRADOR);
		//envia os "projetos" para o JSP (c:foreach)
		request.setAttribute("listaProjetos", projetosAdmin);
		
		return map.findForward("listaRemoveProjetos");
	}
}